<?php

namespace app\user\logic;

use app\model\VaccinesRecord;

class VaccinesRecordLogic
{
    protected VaccinesRecord $model;
    protected int $factory_id;

    public function __construct()
    {
        $this->model = new VaccinesRecord();
        $this->factory_id = request()->user_info['factory_id'];
    }

    /**
     * @Description 列表
     * @author: zj
     * @param array $param
     * @time 2024/03/26 16:47:35
     * @return array
     * @throws \think\db\exception\DbException
     */
    public function getList(array $param)
    {
        $query = $this->model->field('out_id as id,item_name,record_time,create_time')
            ->where('factory_id',$this->factory_id)
            ->where('delete_time',$this->model::IS_DELETE_NO);
        if ($param['pig_id']) {
            $query->where('pig_id',$param['pig_id']);
        }
        if ($param['item_name']) {
            $query->where('item_name','like','%'.trim($param['item_name']).'%');
        }

        return $query->order('out_id DESC')
            ->paginate([
                'list_rows' => $param['page_size'],
                'page' => $param['page']
            ])
            ->toArray();
    }
}